/**
 * @projectName study-note
 * @package Interpreter
 * @className Interpreter.AbstractExpression
 */
package Interpreter;

/**
 * AbstractExpression
 * @description 表达式抽象类
 * @author answer_wx
 * @date 2022/7/6 15:18
 * @version 1.0
 */
public abstract class AbstractExpression {
    /**
     * 解释器
     */
    public void interpreter(Context context) {
        String text = context.getText();
        if (text.isEmpty()) {
            return;
        }
        String playKey = text.substring(0, 1);
        text = text.substring(2);
        double playValue = Double.parseDouble(text.substring(0, text.indexOf(" ")));
        context.setText(text.substring(text.indexOf(" ") + 1));
        execute(playKey, playValue);
    }

    abstract public void execute(String key, double value);
}